package com.windoent.yugioh.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.Toast;

public class ToastUtils {
    private static Toast mToast = null;
    @SuppressLint("StaticFieldLeak")
    private static Context mContext = null;

    public ToastUtils() {
    }

    public static void init(Context context) {
        mContext = context;
    }

    public static void showText(String text) {
        if (mContext != null) {
            if (!TextUtils.isEmpty(text)) {
                if (mToast == null) {
                    mToast = Toast.makeText(mContext.getApplicationContext(), text, Toast.LENGTH_SHORT);
                } else {
                    mToast.setText(text);
                    mToast.setDuration(Toast.LENGTH_SHORT);
                }
                mToast.setGravity(Gravity.CENTER, 0, 0);
                mToast.show();
            }
        }
    }

    public static void showText(int id) {
        if (mContext != null) {
            String text = mContext.getString(id);
            if (mToast == null) {
                mToast = Toast.makeText(mContext.getApplicationContext(), text, Toast.LENGTH_SHORT);
            } else {
                mToast.setText(text);
                mToast.setDuration(Toast.LENGTH_SHORT);
            }
            mToast.setGravity(Gravity.CENTER, 0, 0);
            mToast.show();
        }
    }

    public static void cancel() {
        if (mToast != null) {
            mToast.cancel();
        }

    }

    public static void showText(Context context, String string) {
        if (context != null) {
            if (!TextUtils.isEmpty(string)) {
                if (mToast == null) {
                    mToast = Toast.makeText(context.getApplicationContext(), string, Toast.LENGTH_SHORT);
                } else {
                    mToast.setText(string);
                    mToast.setDuration(Toast.LENGTH_SHORT);
                }
                mToast.setGravity(Gravity.CENTER, 0, 0);
                mToast.show();
            }
        }
    }
}